package cn.admobiletop.adsuyi.adapter.toutiao.listener;

import com.bytedance.sdk.openadsdk.TTAppDownloadListener;

import cn.admobiletop.adsuyi.ADSuyiSdk;
import cn.admobiletop.adsuyi.util.ADSuyiToastUtil;

/**
 * @author ciba
 * @description 头条自定义下载监听
 * @date 2020/04/02
 */
public class CustomDownloadListener implements TTAppDownloadListener {
    private boolean downloading = false;

    @Override
    public void onIdle() {
    }

    @Override
    public void onDownloadActive(long totalBytes, long currBytes, String fileName, String appName) {
        if (!downloading) {
            downloading = true;
            toast(appName + "已开始下载");
        }
    }

    @Override
    public void onDownloadPaused(long totalBytes, long currBytes, String fileName, String appName) {
        if (downloading) {
            downloading = false;
            toast(appName + "已暂停下载");
        }
    }

    @Override
    public void onDownloadFailed(long totalBytes, long currBytes, String fileName, String appName) {
    }

    @Override
    public void onInstalled(String fileName, String appName) {
    }

    @Override
    public void onDownloadFinished(long totalBytes, String fileName, String appName) {
    }

    private void toast(String message) {
        ADSuyiToastUtil.show(ADSuyiSdk.getInstance().getContext(), message);
    }
}
